//
//  TabBarButton.m
//  项目基本框架
//
//  Created by huahua on 17/1/14.
//  Copyright © 2017年 os1. All rights reserved.
//

#import "TabBarButton.h"

@interface TabBarButton (){

    UIImageView *_imageView;
    UILabel *_titleLabel;
}

@end

@implementation TabBarButton

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        _imageView = [[UIImageView alloc] initWithFrame:CGRectZero];
        _imageView.contentMode = UIViewContentModeCenter;
        [self addSubview:_imageView];
        
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.textColor = [UIColor darkGrayColor];
        _titleLabel.font = [UIFont systemFontOfSize:12];
        [self addSubview:_titleLabel];
    }
    return self;
}

- (void)setImageName:(NSString *)imageName{
    if (_imageName != imageName) {
        
        _imageName = imageName;
        _imageView.image = [UIImage imageNamed:_imageName];
    }
}

-(void)setTitleName:(NSString *)titleName{

    if (_titleName != titleName) {
        
        _titleName = titleName;
        _titleLabel.text = _titleName;
    }
}

- (void)layoutSubviews{
    [super layoutSubviews];
    _imageView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height - titleLableH);
    _titleLabel.frame = CGRectMake(0, CGRectGetMaxY(_imageView.frame), self.frame.size.width, titleLableH);
}

@end
